package com.ztman.service.work.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ztman.basic.exception.BizException;
import com.ztman.service.work.dao.WorkOrderInfoMapper;
import com.ztman.service.work.dto.WorkOrderInfoPageQuery;
import com.ztman.service.work.entity.WorkOrderInfo;
import com.ztman.service.work.service.WorkOrderInfoService;
import com.ztman.basic.base.service.SuperServiceImpl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 业务实现类
 *
 * </p>
 *
 * @author wsd
 * @date 2021-08-23
 */
@Slf4j
@Service
public class WorkOrderInfoServiceImpl extends SuperServiceImpl<WorkOrderInfoMapper, WorkOrderInfo> implements WorkOrderInfoService {
    @Override
    public IPage<WorkOrderInfoPageQuery> pageType(IPage<Object> page, WorkOrderInfoPageQuery model) {
        return baseMapper.pageType(page, model);
    }

    @Override
    public WorkOrderInfoPageQuery getWorkOrderInfoById(Long work_order_id) {
        WorkOrderInfo workOrderInfoById = baseMapper.getWorkOrderInfoById(work_order_id);
        if(workOrderInfoById == null){
            throw new BizException("未发现表单数据");
        }
        JSONArray state = workOrderInfoById.getState();
        JSONObject jsonObject = state.getJSONObject(0);
        String id = jsonObject.getString("id");
        WorkOrderInfoPageQuery query = new WorkOrderInfoPageQuery();
        BeanUtils.copyProperties(workOrderInfoById,query);
        query.setCurrent_state(id);
        return query;
    }

    @Override
    public List<Map<String, Object>> workOrderRank(Date date0000, Date date2359) {
        return baseMapper.workOrderRank(date0000, date2359);
    }

    @Override
    public  List<Map<String, Object>>  DateRangeStatistics(Date date0000, Date date2359) {
        return baseMapper.DateRangeStatistics(date0000,date2359);
    }

    @Override
    public  List<Map<String, Object>>  HandlePersonRank(Date date0000, Date date2359) {
        return baseMapper.HandlePersonRank(date0000,date2359);
    }

    @Override
    public  List<Map<String, Object>>  HandlePeriodRank(Date date0000, Date date2359) {
        return baseMapper.HandlePeriodRank(date0000,date2359);
    }
}
